home *** CD-ROM | disk | FTP | other *** search
/ MacFormat 1994 August / August CD.bin / Shareware / Education / numericalmethods Folder / chap_10 / a10_4.m < prev    next >
Encoding:
Text File  |  1994-06-05  |  2.1 KB  |  99 lines  |  [MATS/MATL]

  1. echo off;
  2. % NUMERICAL METHODS: MATLAB Programs, (c) John H. Mathews 1994
  3. % To accompany the text:
  4. % NUMERICAL METHODS for Mathematics, Science and Engineering, 2nd Ed, 1992
  5. % Prentice Hall, Englewood Cliffs, New Jersey, 07632, U.S.A.
  6. % This free software is complements of the author.
  7.  
  8. % Algorithm 10.4 (Dirichlet Method for Laplace's Equation).
  9. % Section    10.3,    Elliptic Equations, Page 531
  10. echo on; clc; format short; hold off; clear
  11.  
  12. % ELLIPTIC EQUATIONS.
  13.  
  14. % Dirichlet solution for the heat equation
  15.  
  16. %            u  (x,y)  +   u  (x,y)  =  0
  17. %             xx            yy
  18.  
  19. % with the boundary values:'
  20.  
  21. % u(x,0) = f1(x), u(x,b) = f2(x)   for 0 ≤ x ≤ a,
  22.  
  23. % u(0,y) = f3(y), u(a,y) = f4(y)   for 0 ≤ y ≤ b,
  24.  
  25. % A numerical approximation is computed over the rectangle
  26.  
  27. %         0 ≤ x ≤ a ,   0 ≤ y ≤ b.
  28.  
  29. pause    % Press any key to continue.
  30.  
  31. clc;
  32. %    Store f1(x),f2(x),f3(y),f4(y) in f1.m f2.m f3.m f4.m
  33.  
  34. % function z = f1(x)
  35. % z = 20;
  36.  
  37. % function z = f2(x)
  38. % z = 180;
  39.  
  40. % function z = f3(y)
  41. % z = 80;
  42.  
  43. % function z = f4(y)
  44. % z = 0;
  45.  
  46. delete f1.m
  47. diary f1.m; disp('function z = f1(x)');...
  48.             disp('z = 20;');...
  49. diary off;
  50.  
  51. delete f2.m
  52. diary f2.m; disp('function z = f2(x)');...
  53.             disp('z = 180;');...
  54. diary off;
  55.  
  56. delete f3.m
  57. diary f3.m; disp('function z = f3(y)');...
  58.             disp('z = 80;');...
  59. diary off;
  60.  
  61. delete f4.m
  62. diary f4.m; disp('function z = f4(y)');...
  63.             disp('z = 0;');...
  64. diary off;
  65.  
  66. % Remark. f1.m f2.m f3.m f4.m dirich.m are used for Algorithm 10.4
  67. f1(0); f2(0); f3(0); f4(0);
  68. pause    % Press any key to continue.
  69.  
  70. clc;
  71. %    Place the endpoint of [0,a] in  a.
  72. %    Place the endpoint of [0,b] in  b.
  73. % Place the step size in  h.
  74. % Place the tolerance in  tol.
  75. % Place the maximum number of iterations in  max1.
  76.  
  77. a  =  4.0;
  78. b  =  4.0;
  79. h  =  0.5;
  80. tol = 0.001;
  81. max1  = 25;
  82.  
  83. % Proceeding with the iteration.
  84.  
  85. U = dirich('f1','f2','f3','f4',a,b,h,tol,max1);
  86.  
  87. pause    % Press any key to see the solution. 
  88.  
  89. clc; clg;
  90. mesh(U);...
  91. Mx1 = 'The solution to Laplace`s equation.';...
  92. title(Mx1);...
  93. shg; pause % Press any key to continue.
  94.  
  95. W = rot90(U);
  96. clc,echo off,diary output,...
  97. disp(' '),disp(Mx1),disp(' '),disp(W),...
  98. diary off,echo on
  99.